Posts

Post not yet marked as solved
6 Replies
What does -didToggleAccessStatus: do? Where is your program stuck? You can potentially see that by taking a process sample (using Activity Monitor or the sample command). Or you can just stop the program in the debugger and see where the various threads are stopped.
Post not yet marked as solved
5 Replies
Assuming your app is an LSUIElement or, equivalently, its activationPolicy is .accessory, then it's not the frontmost application. Some other application is frontmost and displays its main menu in the menu bar. A standard item in the application menu of normal applications is Hide <App Name>. That item's standard keyboard shortcut is Command-H. That's probably overriding your menu item's keyboard shortcut. After all, Command-H can only be associated with one active menu item at a time.Try using a different shortcut.
Post marked as solved
3 Replies
You need to arrange for the key view loop to be set up. Each view has nextKeyView and previousKeyView properties. You can set those manually in IB or programmatically to form a chain through your window's views, but it's usually easiest to let the window manage it. For that, make sure that the window's autorecalculatesKeyViewLoop property is set to true.
Post not yet marked as solved
12 Replies
With respect to 1: Cocoa is the lowest-level API for GUI app programming, but there are lower APIs for some other kinds of programming. There's a whole BSD/POSIX layer. There are various C APIs like Core Foundation, Core Graphics, parts of AddressBook, Core Audio, etc.With respect to 3: Swift is a language. System libraries and frameworks can be accessed by mulitple languages. Besides C, Objective-C, and Swift, there are Fortran, Go, Rust, C++, etc. That doesn't require interpretation or anything like that. The dynamic object-oriented frameworks require a language that supports such features. That includes Objective-C and Swift. C can only (easily) access traditional C-style libraries and frameworks.
Post marked as solved
5 Replies
Is your timer firing on the main thread? If on a background thread, does the timer callback interact with the main thread? Either of those might explain why GUI operations might interfere with the timer.
Post marked as solved
5 Replies
First, you're keeping a strong reference to myActivityRef for the duration, right?Next, I'd try using NSActivityBackground instead of, or perhaps in addition to, NSActivityLatencyCritical. (The latter is documented to say very few apps really need it.) The bit mask values for those two options do not overlap. It's conceivable that NSActivityLatencyCritical without NSActivityBackground is interpreted as only needing lowest latency when in the foreground.If that doesn't do it, try NSActivityUserInitiated.
Post not yet marked as solved
3 Replies
But what is the code going to do with the pid? Why is it trying to obtain the pid?
Post not yet marked as solved
3 Replies
Well, first, "ls" is not an application. It's an executable, sure, but not all executables are applications. It's not appropriate to try to launch it using NSWorkspace, nor would NSRunningApplication properly represent it (because it's not a running application).You should use NSTask to run commands like "ls". (Well, for "ls" specifically, you should use the appropriate directory enumeration APIs and not invoke an external command at all.)What are you intending to use the process identifier for? Perhaps there's a more appropriate way to achieve what you're trying to do.For what it's worth, the docs for -[NSRunningApplication processIdentifier] says it may return -1, but doesn't really explain why. My best guess is for NSRunningApplication objects that represent terminated apps/processes, which don't exist anymore.
Post not yet marked as solved
4 Replies
Replied In Cocoa Bindings
KVO and notifications are not, in themselves, Cocoa Bindings. I mean, you can think of them as ways of binding the view to the controller and model, but they're not "Bindings".Bindings is built on top of KVO and KVC. You also don't necessarily need to use IB to establish bindings. You can do it in code, too, using the -bind:toObject:withKeyPath:options: method of NSKeyValueBindingCreation.You would typically bind the view layer to the controller layer, which would then be bound to the model layer. NSViewController has a representedObject property, which the coordinating controller should set or bind to the relevant part of the model. The coordinating controller would be a document or window controller.
Post not yet marked as solved
5 Replies
It's possible there's a bug in NSRunningApplication, but I'd look elsewhere first. In particular, you may have a memory smashing bug elsewhere in code unrelated to NSRunningApplication.Try the usual "code hygiene" steps. Enable applicable warnings and fix them. Perform static analysis on your code and fix the issues it finds. Run your code with the various sanitizers, especially the thread sanitizer. Run your code under the Zombies template of Instruments.
Post not yet marked as solved
3 Replies
It has never been safe to examine the dynamic class of an object to detect the difference between mutable and immutable. For example, data objects may be represented by an instance of some private internal class which uses a flag to govern its mutability. In order to be usable as either an immutable or mutable data object, that internal class would have to derive from NSMutableData. (This is not hypothetical, it's actually how some Foundation classes have actually been implemented historically.)The secure coding round-trip issue does sound like a problem with this, though.
Post not yet marked as solved
2 Replies
Do you mean you want the PID of the application process that was launched, after you launch it?If you can switch to either -[NSWorkspace launchApplicationAtURL:options:configuration:error:] or -[NSWorkspace openURL:options:configuration:error:], they directly return a reference to the NSRunningApplication.
Post not yet marked as solved
3 Replies
It would be a network share if it's not local: kCFURLVolumeIsLocalKey/NSURLVolumeIsLocalKey.A question you need to ask yourself is whether USB vs. CD/DVD is really the distinction you want. It might be more appropriate to actually base code logic and/or UI on removable or not, ejectable or not, internal or not, etc. Consider, for example, tape drives or other kinds of drives that don't fall into either of your categories.If you really need to know the media type or bus type, that would be where Disk Arbitration would be better. You would create a DADisk reference using DADiskCreateFromVolumePath(). Then you can get its properties using DADiskCopyDescription(). In the returned dictionary, should be a value under the key kDADiskDescriptionMediaKindKey.
Post not yet marked as solved
3 Replies
Some of this information can be obtained from the CFURL/NSURL APIs. Look for the APIs having to do with resource properties, like CFURLCopyResourcePropertyForKey() and the volume property keys.For other information, you may need to use the Disk Arbitration API.
Post marked as solved
6 Replies
If you're willing to disable this throughout your app (rather than for just one class of text view), you can set the user default "NSAutomaticPeriodSubstitutionEnabled" to false somewhere early in startup. I discovered that key name by doing "defaults read -g", toggling that setting in System Preferences, doing "defaults read -g" again, and comparing the output from before and after.